<?php

namespace App\Services;

use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;

class Upload
{
    public static function uploadOss(string $filename): string
    {
        $fa = pathinfo($filename);
        $basename = $fa['basename'];
        $uploadDirectory = 'mini/' . date('Y/m/d', now()->timestamp); //上传目录地址
        $fileName = $uploadDirectory . '/' . $basename; //上传文件名称
        $url = '';
        if (Storage::disk('oss')->put($fileName, file_get_contents($filename))) {
            $url = Storage::disk('oss')->url($fileName);
        }
        Log::info('上传资源到oss url:' . $url);
        return $url;
    }
}
